package com.isky.visual.proj.entity.vo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.isky.visual.proj.entity.Project;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;

/**
 * @author wenjs
 */
@Data
public class ProjectVO {

    private Long id;

//    @ApiModelProperty(value = "分组id")
//    private Long groupId;

    @ApiModelProperty(value = "创建人id")
    private Long userId;

    @ApiModelProperty(value = "发布后的大json")
    private JSONObject projectVisualjson;

    @ApiModelProperty(value = "项目名称")
    private String projectName;

    @ApiModelProperty(value = "创建人")
    private String createBy;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "数据有效性")
    private Boolean valid;

    @ApiModelProperty(value = "状态 0 未发布，1已发布")
    private Integer status;

    @ApiModelProperty(value = "页面图片地址")
    private String imageUrl;


    public Project toProject(){
        Project project = new Project();
        BeanUtils.copyProperties(this,project);
        project.setProjectVisualjson(projectVisualjson.toJSONString());
        return project;
    }

    public void toModel(Project project){
        if(project == null){
            return;
        }
        BeanUtils.copyProperties(project,this);
        this.projectVisualjson = JSON.parseObject(project.getProjectVisualjson());
    }
}
